package cc.magicjson.example.demo.monica;

import java.util.Random;

public class MontyHallProblemByMonica {

    private static final Random random = new Random();

    public static void main(String[] args) {
        int totalSimulations = 1000000;
        int stayWins = 0;
        int switchWins = 0;

        for (int i = 0; i < totalSimulations; i++) {
            int carPosition = random.nextInt(3);
            int initialChoice = random.nextInt(3);

            int revealedGoat;
            do {
                revealedGoat = random.nextInt(3);
            } while (revealedGoat == carPosition || revealedGoat == initialChoice);

            int finalChoice;
            do {
                finalChoice = random.nextInt(3);
            } while (finalChoice == initialChoice || finalChoice == revealedGoat);

            if (initialChoice == carPosition) {
                stayWins++;
            } else if (finalChoice == carPosition) {
                switchWins++;
            }
        }

        double stayWinPercentage = (double) stayWins / totalSimulations * 100;
        double switchWinPercentage = (double) switchWins / totalSimulations * 100;

        System.out.println("不改变选择赢得概率: " + stayWinPercentage + "%");
        System.out.println("改变选择赢得概率: " + switchWinPercentage + "%");
    }
}
